/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.entity;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import org.ipti.br.tag.util.EncryptionUtil;

/**
 *
 * @author israel
 */
@Entity
@Table(name="uf_state")
public class State implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    @Column(name="hash_id")
    private Long id;

    @Column(length=60)
    private String name;
    
    @Column(length=3)
    private String uf;

    public State() {
    }

    @PrePersist
    public void generateHash(){
        if(getId() == null){
            String hash = "" + this.getName();
            this.setId(Long.valueOf(EncryptionUtil.encrypt(hash).hashCode()));
        }
    }

    public State(String name, String uf) {
        this.name = name;
        this.uf = uf;
    }   

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }  

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUf() {
        return uf;
    }

    public void setUf(String uf) {
        this.uf = uf;
    }    
}
